<?php
// +----------------------------------------------------------------------
// | FRANSCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013  All rights reserved.
// +----------------------------------------------------------------------
// | Author:
// +----------------------------------------------------------------------

namespace app\common\model;

/**
 * 友情链接类
 * @author molong <molong@tensent.cn>
 */
class Link extends \app\common\model\Base
{
    protected $auto = array('update_time');

    protected $type = array(
        'cover_id' => 'integer',
        'sort' => 'integer',
    );

    /**
     * 链接类型
     * @var array
     */
    public $ftype = [
        '1' => '普通链接',
        '2' => '合作伙伴',
    ];

    public $keyList = array(
        array('name' => 'id', 'title' => 'ID', 'type' => 'hidden'),
        array('name' => 'title', 'title' => '友链标题', 'type' => 'text', 'help' => ''),
        array('name' => 'url', 'title' => 'URL链接', 'type' => 'text', 'help' => ''),
        array('name' => 'ftype', 'title' => '友链类别', 'type' => 'select', 'option' => [], 'help' => ''),
        array('name' => 'cover_id', 'title' => '网站LOGO', 'type' => 'image', 'help' => ''),
        array('name' => 'status', 'title' => '状态', 'type' => 'select', 'option' => array('1' => '启用', '0' => '禁用'), 'help' => ''),
        array('name' => 'sort', 'title' => '链接排序', 'type' => 'text', 'help' => ''),
        array('name' => 'descrip', 'title' => '描述', 'type' => 'textarea', 'help' => '')
    );

    public function initialize()
    {
        parent::initialize();
        foreach ($this->keyList as $key => $value) {
            if ($value['name'] == 'ftype') {
                $value['option'] = $this->ftype;
            }

            $this->keyList[$key] = $value;
        }
    }

    /**
     * @return string
     */
    public function getFtypeAttr($value, $data)
    {
        return $this->ftype[$data['ftype']];
    }

}